import axios from "axios"


let instance = axios.create({
    baseURL: '',
    headers: {
        'content-type': 'application/json',
        'bypass-tunnel-reminder': 'any-value'
    },
})

// 请求拦截器
instance.interceptors.request.use(function (config) {
    
  //添加请求头
  

    return config
}, function (error) {
    
    return Promise.reject(error)
})

// 响应拦截器
instance.interceptors.response.use(function (response) {
    // 对响应数据做点什么 
    

    return response.data
}, function (err) {

    if(err){
        // store.state.loading = false;
      }
      if (err && err.response) {
          switch (err.response.status) {
            case 400:
              err.message = 'Request Error';
              break
            case 401:
              err.message = 'Unauthorized, please log in';
              break
            case 403:
              err.message = 'no access';
              break
            case 404:
              err.message = 'not found'
              break
            case 408:
              err.message = 'request timeout';
              break
            case 500:
              err.message = 'Server Internal Error';
              break
  
            case 501:
              err.message = 'Service not implemented';
              break
  
            case 502:
              err.message = 'Bad Gateway';
              break
  
            case 503:
              err.message = 'The service is unavailable';
              break
  
            case 504:
              err.message = 'gateway timeout';
              break
  
            case 505:
              err.message = 'HTTP version not supported';
              break
  
          default:
        }
      }
      return Promise.reject(err)
})

export default instance